package comp3021.a1;

public class UserData {
	private UserList users;
	public int UserId;
	private boolean state = false;
	public UserData(String fileName){
	users = new UserList(fileName);
}
public boolean loginByName(String inputUser)
{		 	
	 	for(int i =0;i< users.ulist.size();i++) 
	 	{
		 if( users.ulist.get(i).getName().equals(inputUser) )
		 {
			 UserId=i;					//help us to find the location of user in userlist
			 return true;
		 }
	 	}
	 return false;	//cannot find the username in user's namelist
}
 public boolean loginByPw(String inputPw)
{
	
	if( users.ulist.get(UserId).getKey().equals(inputPw) )
		{	
			 state = true;		//user and pw are both correct,then state  --> true to indicate user successfully log in.  
			 return true;
		} 
	else
	{
		state = false;
		return false;
	}		
}
public void Logout()
{	
	
	state= false;
}


public boolean Status()
 {
	 return state;
 }

}
